/*=================================================================
* 版权信息：Copyright (C) 2005-2011 捷点科技 All Rights Reserved.
* 文件名称：NewsInfoList.cs
* 创建标识：曾乃强 15158756652 2011-3-21 10:12:44
* 修改标识：
* 功能描述：
===================================================================*/
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.Framework;
using CNVP.Framework.Helper;
using System.Data;
using CNVP.JShop.UI;
using CNVP.Framework.Utils;

namespace CNVP.JShop.Web.Admin
{
    public partial class NewsInfoList : AdminPage
    {
        BLL.CNVP_NewsInfo bll = new BLL.CNVP_NewsInfo();
        public int rplistCount = 0;
        public int PageIndex = 1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 76)) return;//判断页面权限
            if (!String.IsNullOrEmpty(Request.QueryString["Page"]) && Public.IsNumber(Request.QueryString["Page"]))
            {
                PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
            }
            if (!IsPostBack)
            {
                ViewState["SearchType"] = "0";
                ColumnBind();
                StartLoad(PageIndex);
                btDelete.Attributes.Add("onclick", "if(ifCheck()){return confirm('确定删除该记录吗?');}else{alert('请选择记录！');return false;};");
            }
            
        }

        private void ColumnBind()
        {
            IList<Model.CNVP_Column> model_Column = new BLL.CNVP_Column().GetAll_CNVP_Column(" ColumnType=2");
            foreach (Model.CNVP_Column m in model_Column)
            {
                ddlColumn.Items.Add(new ListItem(m.ColumnName,m.ID.ToString()));
            }
        }

        /// <summary>
        /// PageNavigator1_PageChange 的摘要说明
        /// 分页加载列表函数
        /// </summary>
        protected void StartLoad(int PageIndex)
        {
            SQLConditionInfo[] st = new SQLConditionInfo[4];
            st[0] = new SQLConditionInfo("@NewsClassID", ddlColumn.SelectedValue);
            st[1] = new SQLConditionInfo("@NewsTitle", Public.FilterSql(txtkey.Text.Trim()));
            st[2] = new SQLConditionInfo("@NewsTitle1", Public.FilterSql(txtkey1.Text.Trim()));
            st[3] = new SQLConditionInfo("@SearchType", ViewState["SearchType"]);
            int i, j;
            DataTable dt = null;
            int pageNum = 20;
            dt = bll.GetPage(this.GetType().Name, PageIndex, pageNum, out i, out j, st);
            rpList.DataSource = dt;
            rpList.DataBind();
            paging.InnerHtml = Paginator.Pagination(PageIndex, i, j);
        }

        protected void btDelete_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.rpList.Items.Count; i++)
            {
                CheckBox cbCheck = (CheckBox)this.rpList.Items[i].FindControl("cbCheck");
                if (cbCheck.Checked == true)
                {
                    int code = int.Parse(cbCheck.ToolTip);
                    new BLL.CNVP_SEOInfo().Delete_CNVP_SEOInfo(new BLL.CNVP_NewsInfo().GetSingle_CNVP_NewsInfoById(code).SeoInfoID);//删除SEO
                    bll.Delete_CNVP_NewsInfo(code);
                    
                }
            }
            StartLoad(1);
        }

        protected void btHighSearch_Click(object sender, EventArgs e)
        {
            ViewState["SearchType"] = "1";
            StartLoad(PageIndex);

        }

        protected void btSearch_Click(object sender, ImageClickEventArgs e)
        {
            ViewState["SearchType"] = "0";
            StartLoad(PageIndex);
        }
    }
}

